import request from '@/utils/request'

export default {

  getList: function (params) {
    return request({
      url: '/shop/category/list',
      method: 'get',
      params
    })
  },

  getCategories: function () {
    return request({
      url: '/shop/category/getAll',
      method: 'get'
    })
  },

  getBanners: function (id) {
    return request({
      url: '/shop/category/getBanners/' + id,
      method: 'get'
    })
  },
  getAttrKeys: function (id) {
    return request({
      url: '/shop/category/getAttrKeys/' + id,
      method: 'get'
    })
  },
  save: function (params) {
    return request({
      url: '/shop/category',
      method: 'post',
      params
    })
  },
  remove: function (id) {
    return request({
      url: '/shop/category',
      method: 'delete',
      params: {
        id: id
      }
    })
  },
  removeBanner: function (id, idBanner) {
    return request({
      url: '/shop/category/removeBanner/' + id + '/' + idBanner,
      method: 'delete'
    })
  },
  setCategoryBanner: function (id, idBanner) {
    return request({
      url: '/shop/category/setBanner/' + id + '/' + idBanner,
      method: 'post'
    })
  },
  getOpenFirstCategory: function () {
    return request({
      url: '/shop/categoryFirst/getOpenFirstCategory',
      method: 'get',
    })
  },
  findByFirstId: function (params) {
    return request({
      url: '/shop/category/findByFistId',
      method: 'post',
      params
    })
  },
  getFirstCategoryAndSecond: function (params) {
    return request({
      url: 'shop/categoryFirst/getFirstCategoryAndSecond',
      method: 'get',
      params
    })
  },

  // 获取所有一级分类
  getAllFirstCategory: function () {
    return request({
      url: '/shop/categoryFirst/list',
      method: 'get',
    })
  },
  // 根据一级分类获取二级分类
  getSecondClassByFirstClassId: function (params) {
    return request({
      url: '/shop/category/findByFistId',
      method: 'post',
      params: {
        id: params.id
      }
    })
  },
  // 获取所有热门分类
  getAllHotCategory: function () {
    return request({
      url: '/shop/category/getHotCategory',
      method: 'get',
    })
  },
  // 将某个二级分类设置成热门分类
  updateSecondClassIsHot: function (params) {
    return request({
      url: '/shop/category/upDateIsHot',
      method: 'post',
      params: {
        id: params.id,
        isHot: params.isHot
      }
    })
  },
  // 修改热门分类排序字段
  updateHotSort: function (params) {
    return request({
      url: '/shop/category/updateDesc',
      method: 'post',
      params: {
        id: params.id,
        sort: params.sort
      }
    })
  },
}
